home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / util / moni / Scout-src.lha / src / objects / scout_classes.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-09  |  8.5 KB  |  250 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "scout_classes.h"
  31.  
  32. extern struct ExecBase  *SysBase;
  33.  
  34. int  classcnt;
  35.  
  36. APTR classmoretext0,classmoretext1,classmoretext2,classmoretext3,classmoretext4;
  37.  
  38. struct Remember *ClassRememberKey;
  39.  
  40. __asm LONG classlist_dspfunc(register __a2 char **array, register __a1 struct ClassEntry *classentry, register __a0 struct Hook *hook) {
  41.    if (classentry) {
  42.       *array++ = classentry->cse_address;
  43.       *array++ = classentry->cse_objcnt;
  44.       *array++ = classentry->cse_subcnt;
  45.       *array++ = classentry->cse_super;
  46.       *array++ = classentry->cse_dispatch;
  47.       *array   = classentry->cse_classname;
  48.    } else {
  49.       *array++ = ESC "bAddress";
  50.       *array++ = ESC "bObjects";
  51.       *array++ = ESC "bSubclasses";
  52.       *array++ = ESC "bSuperclass";
  53.       *array++ = ESC "bDispatcher";
  54.       *array   = ESC "bName";
  55.    }
  56.    return (0);
  57. }
  58.  
  59. struct Hook classlist_dsphook = {
  60.  {NULL, NULL},
  61.  (ULONG (* )())classlist_dspfunc,
  62.  NULL, NULL
  63. };
  64.  
  65. void FFreeClass (void) {
  66.    MyFreeStructs (&ClassRememberKey, classtext, classlist);
  67. }
  68.  
  69. int GetClass (struct ClassEntry **first) {
  70.    struct   ClassEntry   *classentry,*previous = NULL;
  71.  
  72.    int classcnt = 0;
  73.    *first = 0;
  74.  
  75.    if (clientstate) {
  76.       if (SendDaemon ("GetClassList")) {
  77.          while ((classentry = AllocRemember (&ClassRememberKey, sizeof (struct ClassEntry), MEMF_ANY|MEMF_CLEAR)) \
  78.            && (ReceiveDecodedEntry ((UBYTE *) classentry, sizeof (struct ClassEntry)))) {
  79.             IsHex (classentry->cse_address, (long *) &classentry->cse_adr);
  80.  
  81.             if (! *first)
  82.                *first = classentry;
  83.             if (previous)
  84.                previous->cse_next = classentry;
  85.  
  86.             classcnt++;
  87.             previous = classentry;
  88.          }
  89.       }
  90.    } else {
  91.       struct IClass *myclass = MakeClass("« Scout Dummy Class »","rootclass",NULL,0,0);
  92.       struct Node *clist;
  93.       struct Hook *disp;
  94.  
  95.       if(myclass) {
  96.          AddClass(myclass);
  97.          Forbid();
  98.             for(clist=(struct Node *)&myclass->cl_Dispatcher.h_MinNode; clist->ln_Pred; clist=clist->ln_Pred);   /* Search the list head */
  99.             for(clist=clist->ln_Succ; clist->ln_Succ; clist=clist->ln_Succ) {
  100.                if(clist==(struct Node *)myclass) continue;         /* Skip own dummy */
  101.                if(classentry = AllocRemember (&ClassRememberKey, sizeof(struct ClassEntry), MEMF_ANY|MEMF_CLEAR)) {
  102.  
  103.                   disp = &((struct IClass *)clist)->cl_Dispatcher;
  104.  
  105.                   classentry->cse_adr = (struct IClass *)clist;
  106.                   sprintf(classentry->cse_address,"$%08lx",clist);
  107.                   sprintf(classentry->cse_super,"$%08lx",((struct IClass *)clist)->cl_Super);
  108.                   sprintf(classentry->cse_dispatch,"$%08lx",(disp->h_SubEntry ? disp->h_SubEntry : disp->h_Entry));
  109.                   strncpy(classentry->cse_classname,((struct IClass *)clist)->cl_ID,79);
  110.                   sprintf(classentry->cse_objcnt,"%ld",((struct IClass *)clist)->cl_ObjectCount);
  111.                   sprintf(classentry->cse_subcnt,"%ld",((struct IClass *)clist)->cl_SubclassCount);
  112.  
  113.                   if (! *first)
  114.                      *first = classentry;
  115.                   if (previous)
  116.                      previous->cse_next = classentry;
  117.                   classcnt++;
  118.                   previous = classentry;
  119.                }
  120.             }
  121.           Permit();
  122.           FreeClass(myclass);
  123.       }
  124.    }
  125.    return (classcnt);
  126. }
  127.  
  128. void PrintClass (char *filename) {
  129.    int   i=1;
  130.    BPTR  handle;
  131.    struct ClassEntry *entryp;
  132.  
  133.    handle = HandlePrintStart (filename);
  134.    if ((handle) && (PrintOneLine (handle, "\n  Address  Objects  Subclasses  Superclass  Dispatcher  Name\n\n"))) {
  135.       if (! WI_Class) {
  136.          i = GetClass (&entryp);
  137.       }
  138.       if (i) {
  139.          for (i=0;;i++) {
  140.             if (WI_Class)
  141.                DoMethod (classlist,MUIM_List_GetEntry,i,&entryp);
  142.             if (!entryp) break;
  143.  
  144.             sprintf (tmpstr2, " %ls %7ls %11ls  %ls   %ls   %ls\n", entryp->cse_address, entryp->cse_objcnt, entryp->cse_subcnt, entryp->cse_super, entryp->cse_dispatch, entryp->cse_classname);
  145.             if (! (PrintOneLine (handle, tmpstr2)))
  146.                break;
  147.  
  148.             if (! WI_Class)
  149.                entryp = entryp->cse_next;
  150.          }
  151.       }
  152.    }
  153.    HandlePrintStop();
  154. }
  155.  
  156. void ShowClass (void) {
  157.    struct   ClassEntry   *clas;
  158.  
  159.    ApplicationSleep();
  160.    set(classlist,MUIA_List_Quiet,TRUE);
  161.    set(classlist,MUIA_List_CompareHook,classlist_cmphook_ptr);
  162.    set(BT_ClassRemove, MUIA_Disabled, TRUE);
  163.    set(BT_ClassMore, MUIA_Disabled, TRUE);
  164.    FFreeClass();
  165.  
  166.    classcnt = GetClass (&clas);
  167.  
  168.    while (clas) {
  169.       InsertSortedEntry (classlist, (APTR *) &clas);
  170.       clas = clas->cse_next;
  171.    }
  172.  
  173.    SetCountText (classcount, classcnt);
  174.    AwakeApplication();
  175.    set(classlist,MUIA_List_Quiet,FALSE);
  176. }
  177.  
  178. void SendClassList (void) {
  179.    struct   ClassEntry   *clas;
  180.  
  181.    FFreeClass();
  182.    GetClass (&clas);
  183.  
  184.    while (clas) {
  185.       SendEncodedEntry ((UBYTE *) clas, sizeof (struct ClassEntry));
  186.       clas = clas->cse_next;
  187.    }
  188.    FFreeClass();
  189. }
  190.  
  191. void GetClassMore (struct IClass *bc) {
  192.    unsigned char     *title = "CLASS: ";
  193.    struct   WinFree  *ptr;
  194.    BOOL found = FALSE;
  195.    struct IClass *myclass = MakeClass("« Scout Dummy Class »","rootclass",NULL,0,0);
  196.    struct Node *clist;
  197.  
  198.    if(myclass) {
  199.       AddClass(myclass);
  200.       Forbid();
  201.          for(clist=(struct Node *)&myclass->cl_Dispatcher.h_MinNode; clist->ln_Pred; clist=clist->ln_Pred);   /* Search the list head */
  202.          for(clist=clist->ln_Succ; clist->ln_Succ; clist=clist->ln_Succ) {
  203.             if(clist==(struct Node *)myclass) continue;         /* Skip own dummy */
  204.             if(clist==(struct Node *)bc) {
  205.                found = TRUE;
  206.                break;
  207.             }
  208.          }
  209.        Permit();
  210.        FreeClass(myclass);
  211.    }
  212.  
  213.    if (found && (ptr = AllocWinFree())) {
  214.       ptr->wf_Window = (APTR) WindowObject,
  215.       MUIA_HelpNode, ClassesText,
  216.       MUIA_Window_ID, MakeDetailID('.','C','L','S'),
  217.       WindowContents, VGroup,
  218.          Child, ColGroup(2),
  219.             Child, MyLabel2 ("Name:"),
  220.             Child, classmoretext0 = MyTextObject(),
  221.             Child, MyLabel2 ("Super:"),
  222.             Child, classmoretext1 = MyTextObject(),
  223.          End,
  224.          Child, HGroup,
  225.             Child, MyLabel2 ("Address:\nSuper:\nInstOffset:\nInstSize:"),
  226.             Child, classmoretext2 = MyTextObject2(),
  227.             Child, HSpace(0),
  228.             Child, MyLabel2 ("Entry:\nSubEntry:\nData:\nUserData:"),
  229.             Child, classmoretext3 = MyTextObject2(),
  230.             Child, HSpace(0),
  231.             Child, MyLabel2 ("SubClasses:\nObjects:\nFlags:\nReserved:"),
  232.             Child, classmoretext4 = MyTextObject2(),
  233.          End,
  234.       End, End;
  235.  
  236.       if (ptr->wf_Window) {
  237.          MySetContentsHealed (classmoretext0, "%s", bc->cl_ID);
  238.          MySetContentsHealed (classmoretext1, "%s", bc->cl_Super ? bc->cl_Super->cl_ID : (STRPTR)"---");
  239.          MySetContents (classmoretext2, ESC "r$%08x\n" ESC "r$%08lx\n" ESC "r%ld\n" ESC "r%ld", bc, bc->cl_Super, bc->cl_InstOffset, bc->cl_InstSize);
  240.          MySetContents (classmoretext3, ESC "r$%08x\n" ESC "r$%08lx\n" ESC "r$%08lx\n" ESC "r$%08lx", bc->cl_Dispatcher.h_Entry, bc->cl_Dispatcher.h_SubEntry, bc->cl_Dispatcher.h_Data, bc->cl_UserData);
  241.          MySetContents (classmoretext4, ESC "r%ld\n" ESC "r%ld\n" ESC "r$%08lx\n" ESC "r$%08lx", bc->cl_SubclassCount, bc->cl_ObjectCount, bc->cl_Flags, bc->cl_Reserved);
  242.  
  243. //*         HandleFlagsButtonPressed (classmoretext4, ptr, "(COMMODITY)", "Flags", bc->mco_Flags, (struct LongFlag *) &bc_flags, NULL, 'b');
  244.          HandleWindowOpen (ptr, title, bc->cl_ID);
  245.          HandleWindowClose (ptr);
  246.       }
  247.    }
  248. }
  249.  
  250.